/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dp1.titandevelop.titano.view.almac;

import dp1.titandevelop.titano.bean.Mensajes;
import dp1.titandevelop.titano.persistent.Almacen;
import dp1.titandevelop.titano.persistent.Empleado;
import dp1.titandevelop.titano.persistent.Producto;
import dp1.titandevelop.titano.persistent.TipoMovimiento;
import dp1.titandevelop.titano.service.AlmacenService;
import dp1.titandevelop.titano.service.AlmacenXProductoService;
import dp1.titandevelop.titano.service.EmpleadoService;
import dp1.titandevelop.titano.service.KardexService;
import dp1.titandevelop.titano.service.TipoMovimientoService;
import dp1.titandevelop.titano.service.ValidacionService;
import dp1.titandevelop.titano.view.MensajeError;
import java.awt.Cursor;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;

/**
 *
 * @author Yulian
 */
public class ModulosT_ALM_MovMatNuevo extends javax.swing.JInternalFrame {

    //Para los cboxes
    private List<Almacen> listaAlm;
    private List<Producto> listaProd;
    private List<TipoMovimiento> listaTMov;
    private List<Empleado> listaEmp;
    
    private Mensajes sms = new Mensajes();
    
    private void addList (){
        
        for(int i=0;i<listaAlm.size();i++){
            this.cboxAlmacen.addItem(listaAlm.get(i).getDescripcion());
        }
        for(int i=0;i<listaTMov.size();i++){
            this.cboxTMov.addItem(listaTMov.get(i).getDescripcion());
        }
        for(int i=0;i<listaEmp.size();i++){
            this.cboxResponsable.addItem(listaEmp.get(i).getNombres() +" "+ listaEmp.get(i).getApellidop());
        }        
    }
    public ModulosT_ALM_MovMatNuevo() {
        initComponents();
        
        ValidacionService val = new ValidacionService();
        val.SNumeros(txtCantidad);
        val.Longitud(txtCantidad,9);
        
        val.NoEscribe(dpFechaIn);
        val.NoEscribe(dpFechaFin);
        
        AlmacenService servAlm = new AlmacenService();
        EmpleadoService servEmp = new EmpleadoService();
        
        this.listaAlm = servAlm.buscar();
        this.listaProd = new ArrayList<Producto>();//servProd.buscar();
        this.listaTMov = new ArrayList<TipoMovimiento>();//servTMov.buscar();
        this.listaEmp = servEmp.buscar();
        addList();
    }
    public boolean cboxVacio(JComboBox cbox){
        int index=cbox.getSelectedIndex()-1;
        if(index==-1)
            return true;
        else
            return false;
    }
    public int cboxIndex(JComboBox cbox){
        return cbox.getSelectedIndex()-1;
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        cboxAlmacen = new javax.swing.JComboBox();
        cboxProducto = new javax.swing.JComboBox();
        cboxTMov = new javax.swing.JComboBox();
        txtCantidad = new javax.swing.JTextField();
        cboxResponsable = new javax.swing.JComboBox();
        btnGuardar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        dpFechaIn = new org.jdesktop.swingx.JXDatePicker();
        dpFechaFin = new org.jdesktop.swingx.JXDatePicker();

        setTitle("Nuevo Movimiento de Material");

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos del Movimiento"));

        jLabel2.setText("Almacén");

        jLabel3.setText("Producto");

        jLabel4.setText("Tipo de Movimiento");

        jLabel5.setText("Cantidad");

        jLabel6.setText("Responsable");

        cboxAlmacen.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccionar" }));
        cboxAlmacen.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cboxAlmacenItemStateChanged(evt);
            }
        });
        cboxAlmacen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboxAlmacenActionPerformed(evt);
            }
        });

        cboxProducto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccionar" }));
        cboxProducto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboxProductoActionPerformed(evt);
            }
        });

        cboxTMov.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccionar" }));
        cboxTMov.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboxTMovActionPerformed(evt);
            }
        });

        cboxResponsable.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccionar" }));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addGap(15, 15, 15)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cboxProducto, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cboxAlmacen, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(25, 25, 25)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(cboxTMov, 0, 140, Short.MAX_VALUE)
                            .addComponent(cboxResponsable, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addGap(15, 15, 15)
                        .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(6, 6, 6))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel2)
                    .addComponent(cboxAlmacen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cboxResponsable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(cboxTMov, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(cboxProducto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8))
        );

        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/grabar.png"))); // NOI18N
        btnGuardar.setToolTipText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/cancelar.png"))); // NOI18N
        btnCancelar.setToolTipText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Caracteristicas del Lote"));

        jLabel7.setText("Fecha de Vencimiento ");

        jLabel1.setText("Fecha Ingreso");

        dpFechaIn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dpFechaInActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(dpFechaIn, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(dpFechaFin, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(dpFechaFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dpFechaIn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, 0)
                        .addComponent(btnCancelar))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addGap(8, 8, 8))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnGuardar)
                    .addComponent(btnCancelar))
                .addGap(8, 8, 8))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(1, 1, 1))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        
        
        ValidacionService val = new ValidacionService();
        
        int indexAlm =cboxIndex(cboxAlmacen), idAlm;
        int indexProd = cboxIndex(cboxProducto), idProd;
        int indexTMov = cboxIndex(cboxTMov), idTMov;
        int indexEmp = cboxIndex(cboxResponsable), idEmp;
        
        //Caso en el que todos los cbox son seleccionados
        if(!val.esCBoxVacio(cboxAlmacen)&&!val.esCBoxVacio(cboxProducto)&&!val.esCBoxVacio(cboxTMov)&&!val.esCBoxVacio(cboxResponsable)&&!val.esVacio(txtCantidad)&&!val.esFechaVacia(dpFechaIn)&&!val.esFechaVacia(dpFechaFin)){
            
            idAlm=listaAlm.get(indexAlm).getIdalmacen();
            idProd=listaProd.get(indexProd).getIdproducto();
            idTMov=listaTMov.get(indexTMov).getIdtipomovimiento();            
            idEmp=listaEmp.get(indexEmp).getIdempleado();
            String cad = listaTMov.get(indexTMov).getDescripcion();
            try {
                //Cantidad a ingresar o retirar
                int cant = Integer.parseInt(this.txtCantidad.getText());
                KardexService serv = new KardexService();
                TipoMovimientoService tm = new TipoMovimientoService();
                //Cantidad disponible en dicho almacen para tal producto
                List<Integer> disponible =serv.disponibilidad(idAlm,idProd);
                
                if((disponible.get(0)>=cant && tm.verificaTipoMov(listaTMov.get(indexTMov).getDescripcion(),"Entrada"))||//Caso de entrada de prod a almacen
                   (disponible.get(1)>=cant && tm.verificaTipoMov(listaTMov.get(indexTMov).getDescripcion(),"Salida"))){ //Caso de salida de un prod de almacen
                   
                    this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    serv.insertar(idAlm,idProd,idTMov,idEmp,this.dpFechaIn.getDate(),this.dpFechaFin.getDate(),cant);            
                    this.setCursor(Cursor.getDefaultCursor());
                    
                    JOptionPane.showInternalMessageDialog(this.getRootPane(),sms.getRegistrado(),"Mensaje",JOptionPane.INFORMATION_MESSAGE);

                    ModulosT_ALM.menuAdmMov = new ModulosT_ALM_AdmMovMat();
                    this.getParent().add( ModulosT_ALM.menuAdmMov);
                    Dimension desktopSize = this.getParent().getSize();
                    Dimension jInternalFrameSize =  ModulosT_ALM.menuAdmMov.getSize();
                    ModulosT_ALM.menuAdmMov.setLocation((desktopSize.width - jInternalFrameSize.width) / 2,
                            (desktopSize.height - jInternalFrameSize.height)/4 );
                    ModulosT_ALM.menuAdmMov.show();

                    this.dispose();
                }
                else{
                    JOptionPane.showInternalMessageDialog(this.getRootPane(),"El almacén no tiene capacidad disponible para dicha operación!!\nDisponibilidad para el producto: "+disponible.get(0)+"\nStock del producto en almacén: "+disponible.get(1)+"","Aviso",JOptionPane.WARNING_MESSAGE);
                }
            } catch(Exception e) {
                JOptionPane.showInternalMessageDialog(this.getRootPane(),sms.getError(),"Error",JOptionPane.ERROR_MESSAGE);
            }
        }
        else{
            JOptionPane.showInternalMessageDialog(this.getRootPane(),sms.getCompletarCampos(),"Aviso",JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
       
        ModulosT_ALM.menuAdmMov = new ModulosT_ALM_AdmMovMat();
        this.getParent().add(ModulosT_ALM.menuAdmMov);

        Dimension desktopSize = this.getParent().getSize();
        Dimension jInternalFrameSize = ModulosT_ALM.menuAdmMov.getSize();
        ModulosT_ALM.menuAdmMov.setLocation((desktopSize.width - jInternalFrameSize.width) / 2,
                    (desktopSize.height - jInternalFrameSize.height)/4 );

        ModulosT_ALM.menuAdmMov.show();
        this.dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void cboxAlmacenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboxAlmacenActionPerformed
        AlmacenXProductoService servProd = new AlmacenXProductoService();
        int index=cboxAlmacen.getSelectedIndex()-1;
        int id = listaAlm.get(index).getIdalmacen();
        listaProd= servProd.buscarProductosxIdAlm(id);
        int tam=listaProd.size();
        this.cboxProducto.removeAllItems();
        this.cboxProducto.addItem("Seleccionar");
        for(int i=0;i<tam;i++){
            this.cboxProducto.addItem(listaProd.get(i).getDescripcion());
        }
    }//GEN-LAST:event_cboxAlmacenActionPerformed

    private void cboxTMovActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboxTMovActionPerformed
        
        
//        TipoMovimientoService servTMov = new TipoMovimientoService();
//        List<TipoMovimiento> tipos = servTMov.buscar();
//        
//        int index=cboxProducto.getSelectedIndex()-1;
//        TipoProducto tp= listaProd.get(index).getToTipoProducto();
//        
//        if (tp.getDescripcion().compareTo("Insumo")==0)
//            for(int i=0;i<tipos.size();i++){
//                if(tipos.get(i).getDescripcion().compareTo("Entrada Externa")==0)
//                    this.cboxTMov.addItem(tipos.get(i).getDescripcion());
//                else if(tipos.get(i).getDescripcion().compareTo("Salida Interna")==0)
//                        this.cboxTMov.addItem(tipos.get(i).getDescripcion());                                        
//            }
//        else if (tp.getDescripcion().compareTo("Producto Intermedio")==0)
//            for(int i=0;i<tipos.size();i++){
//                if(tipos.get(i).getDescripcion().compareTo("Entrada Interna")==0)
//                    this.cboxTMov.addItem(tipos.get(i).getDescripcion());
//                else if(tipos.get(i).getDescripcion().compareTo("Salida Interna")==0)
//                        this.cboxTMov.addItem(tipos.get(i).getDescripcion());                                        
//            }
//        else if (tp.getDescripcion().compareTo("Producto Terminado")==0)
//            for(int i=0;i<tipos.size();i++){
//                if(tipos.get(i).getDescripcion().compareTo("Entrada Interna")==0)
//                    this.cboxTMov.addItem(tipos.get(i).getDescripcion());
//                else if(tipos.get(i).getDescripcion().compareTo("Salida Externa")==0)
//                        this.cboxTMov.addItem(tipos.get(i).getDescripcion());                                        
//            }
    }//GEN-LAST:event_cboxTMovActionPerformed

    private void dpFechaInActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dpFechaInActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_dpFechaInActionPerformed

    private void cboxAlmacenItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboxAlmacenItemStateChanged
        

    }//GEN-LAST:event_cboxAlmacenItemStateChanged

    private void cboxProductoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboxProductoActionPerformed
        TipoMovimientoService servTMov = new TipoMovimientoService();
        List<TipoMovimiento> tipos = servTMov.buscar();
        cboxTMov.removeAllItems();
        cboxTMov.addItem("Seleccionar");
        for(int i=0;i<tipos.size();i++){
            this.cboxTMov.addItem(tipos.get(i).getDescripcion());
            listaTMov.add(tipos.get(i));
        }
//        int index=cboxProducto.getSelectedIndex()-1;
//        TipoProducto tp= listaProd.get(index).getToTipoProducto();
//        
//        if (tp.getDescripcion().compareTo("Insumo")==0)
//            for(int i=0;i<tipos.size();i++){
//                if(tipos.get(i).getDescripcion().compareTo("Entrada Externa")==0){
//                    this.cboxTMov.addItem(tipos.get(i).getDescripcion());
//                    listaTMov.add(tipos.get(i));
//                }
//                else if(tipos.get(i).getDescripcion().compareTo("Salida Interna")==0){
//                        this.cboxTMov.addItem(tipos.get(i).getDescripcion()); 
//                        listaTMov.add(tipos.get(i));
//                }
//            }
//        else if (tp.getDescripcion().compareTo("Producto Intermedio")==0)
//            for(int i=0;i<tipos.size();i++){
//                if(tipos.get(i).getDescripcion().compareTo("Entrada Interna")==0){
//                    this.cboxTMov.addItem(tipos.get(i).getDescripcion());
//                    listaTMov.add(tipos.get(i));
//                }
//                else if(tipos.get(i).getDescripcion().compareTo("Salida Interna")==0){
//                        this.cboxTMov.addItem(tipos.get(i).getDescripcion());         
//                        listaTMov.add(tipos.get(i));
//                }                               
//            }
//        else if (tp.getDescripcion().compareTo("Producto Terminado")==0)
//            for(int i=0;i<tipos.size();i++){
//                if(tipos.get(i).getDescripcion().compareTo("Entrada Interna")==0){
//                    this.cboxTMov.addItem(tipos.get(i).getDescripcion());
//                    listaTMov.add(tipos.get(i));
//                }
//                else if(tipos.get(i).getDescripcion().compareTo("Salida Externa")==0){
//                        this.cboxTMov.addItem(tipos.get(i).getDescripcion());         
//                        listaTMov.add(tipos.get(i));
//                }                               
//            }
    }//GEN-LAST:event_cboxProductoActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JComboBox cboxAlmacen;
    private javax.swing.JComboBox cboxProducto;
    private javax.swing.JComboBox cboxResponsable;
    private javax.swing.JComboBox cboxTMov;
    private org.jdesktop.swingx.JXDatePicker dpFechaFin;
    private org.jdesktop.swingx.JXDatePicker dpFechaIn;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTextField txtCantidad;
    // End of variables declaration//GEN-END:variables
}
